package com.ruoyi.house.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.util.BeanUtils;
import com.ruoyi.house.domain.Dto.request.ReqAtbHouse;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house.domain.AtbHouse;
import com.ruoyi.house.service.IAtbHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房屋基础Controller
 * 
 * @author ruoyi
 * @date 2024-09-16
 */
@RestController
@RequestMapping("/house/house")
public class AtbHouseController extends BaseController
{
    @Autowired
    private IAtbHouseService atbHouseService;

    /**
     * 查询房屋基础列表
     */
    @PreAuthorize("@ss.hasPermi('house:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(AtbHouse atbHouse)
    {
        startPage();
        List<AtbHouse> list = atbHouseService.selectAtbHouseList(atbHouse);
        return getDataTable(list);
    }

    /**
     * 导出房屋基础列表
     */
    @PreAuthorize("@ss.hasPermi('house:house:export')")
    @Log(title = "房屋基础", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AtbHouse atbHouse)
    {
        List<AtbHouse> list = atbHouseService.selectAtbHouseList(atbHouse);
        ExcelUtil<AtbHouse> util = new ExcelUtil<AtbHouse>(AtbHouse.class);
        util.exportExcel(response, list, "房屋基础数据");
    }

    /**
     * 获取房屋基础详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        AtbHouse atbHouse = atbHouseService.selectAtbHouseById(id);
        ReqAtbHouse reqAtbHouse = BeanUtil.toBean(atbHouse, ReqAtbHouse.class);
        return success(atbHouse);
    }

    /**
     * 新增房屋基础
     */
    @PreAuthorize("@ss.hasPermi('house:house:add')")
    @Log(title = "房屋基础", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AtbHouse atbHouse)
    {
        return toAjax(atbHouseService.insertAtbHouse(atbHouse));
    }

    /**
     * 修改房屋基础
     */
    @PreAuthorize("@ss.hasPermi('house:house:edit')")
    @Log(title = "房屋基础", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AtbHouse atbHouse)
    {
        return toAjax(atbHouseService.updateAtbHouse(atbHouse));
    }

    /**
     * 删除房屋基础
     */
    @PreAuthorize("@ss.hasPermi('house:house:remove')")
    @Log(title = "房屋基础", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(atbHouseService.deleteAtbHouseByIds(ids));
    }
}
